﻿
@{
    Layout = "";
}
<div ng-controller="ProductListCtrl">
    <!-- 类别切换 -->
    <div class="flayout_c_tabBox j_tabBox">
        <ul>
            <li class="{{CurrentFcId == 0 ? 'home active' : 'home'}}" ng-click="Reload(0,0)">
                <div class="fliconBox">
                    <img src="/Content/images/f_57.png" alt="全部">
                </div>
                <span>全部</span>
            </li>
            <li  ng-repeat="fc in FirstCategoryList" class="{{CurrentFcId==fc.Id?'active':''}}" ng-click="GetSecondCategory(fc.Id)">
                <div class="fliconBox">
                    <img style="width:90%;height:90%;" ng-src="{{ImgHostUrl+fc.PicUrl}}" alt="{{fc.CategoryName}}">
                </div>
                <span>{{fc.CategoryName}}</span>
            </li>

        </ul>
    </div>
    <div class="clear"></div>
    <!--end 类别切换 -->
    <!-- 点击上面的分类显示出来的，二级分类 -->
    <div class="flayout_j_typeMainBox">
        <div class="j_each_type" style="display:block;" ng-show="SecondCategoryShow">
            <ul>
                <li ng-click="Reload(CurrentFcId,0)">
                        <div class="j_type_img">
                            <img src="/Content/images/f_65.png" alt="全部">
                        </div>
                        <p class="j_type_txt">全部</p>
                </li>
                <li ng-repeat="sc in SecondCategoryList" ng-click="Reload(sc.ParentId,sc.Id)">
                    <div class="j_type_img">
                        <img ng-src="{{ImgHostUrl+sc.PicUrl}}" alt="{{sc.CategoryName}}">
                    </div>
                    <p class="j_type_txt">{{sc.CategoryName}}</p>
                </li>

            </ul>
            <!-- 清除浮动 -->
            <div class="clear"></div>
            <!-- 清除浮动 -->
        </div>
    </div>
    <!--end 点击上面的分类显示出来的，二级分类 -->
    <!-- 产品列表 -->
    <section class="list_m_mdv srp">
        <div class="tile_box prolist1" infinite-scroll='reddit.nextPage()' infinite-scroll-disabled='reddit.busy' infinite-scroll-distance='0'>
            <div ui-sref="shop.productdetail({sku:product.Sku,activityId:0})" class="tile_item" ng-repeat="product in reddit.items">
                <div class="ti_img_wrap ">
                    <img ng-src="{{ImgHostUrl+product.ImgUrl}}" class="ti_img">
                </div>
                <div class="ti_info">
                    <p class="tii_title">{{product.Name}}</p>
                    <div class="tii_price"><i class="list_m_font">¥</i>{{product.Price}}<span class="tii_sold"><i>¥{{product.MarketPrice}}</i></span></div>
                </div>
            </div>

        </div>
    </section>
    <div class="clear"></div>
    <!-- end产品列表 -->
</div>

<script type="text/javascript">
    App.controller('ProductListCtrl', [
            '$scope', '$http', '$rootScope', 'Reddit', '$stateParams', '$state', '$filter',
        function ($scope, $http, $rootScope, Reddit, $stateParams, $state, $filter) {
            //console.log($stateParams.fcId)
            $scope.CurrentFcId = ($stateParams.fcId == undefined ? 0 : $stateParams.fcId);
            $scope.SecondCategoryShow = false;


            //数据初始化
            $http.post("/Product/GetCategoryList", {}).then(function (response) {
                $scope.CategoryList = response.data;
                $scope.FirstCategoryList = $filter('filter')(response.data, function (item) { return item.ParentId === 0; });

                var liNum = $scope.FirstCategoryList.length + 1;
                var parameter = 70;
                $(".j_tabBox ul").css("width", liNum * parameter);

                //获取二级分类
                $scope.GetSecondCategory = function (fcid) {
                    if ($scope.CurrentFcId == fcid && $scope.SecondCategoryShow)
                    {
                        $scope.SecondCategoryShow = false;
                    } else
                    {
                        $scope.SecondCategoryShow = true;
                    }
                    $scope.SecondCategoryList = $filter('filter')($scope.CategoryList, function (item) { return item.ParentId === fcid; });
                    $scope.CurrentFcId = fcid;
                }
            });

            var tt = function () {
                $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
            }

            setTimeout(tt, 1000)

            //数据初始化
            $scope.reddit = new Reddit("/Product/ProductList", { Take: 6, Keywords: $stateParams.keywords, fcId: $stateParams.fcId, scId: $stateParams.scId }, function (response) {

            });
            //console.log($scope.reddit);
            //$scope.reddit.nextPage();

            $scope.Reload = function (fcid,scid) {
                $scope.reddit.items = [];
                $scope.reddit.requestData.skip = 0;
                $scope.reddit.requestData.Keywords = "";
                $scope.reddit.requestData.fcId = fcid;
                $scope.reddit.requestData.scId = scid;
                $scope.reddit.all = false;
                $scope.reddit.nextPage();
                $scope.CurrentFcId = fcid;
                $scope.SecondCategoryShow = false;
            };


        }]);
</script>
